package org.social.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.error.GMErrorCode;
import org.social.db.bean.InterceptInfo;
import org.social.db.cache.InterceptInfoCache;
import org.social.manager.InterceptManager;

import com.dal.gm_api.api.IGameIntercept;
import com.sojoys.artifact.tools.ToolError;
import com.xiaoleilu.hutool.collection.CollUtil;
import com.xiaoleilu.hutool.util.ArrayUtil;

/**
 * 拦截
 * Created by fxf on 2017-12-20.
 */
public class GameInterceptServer implements IGameIntercept {

    /**
     * 添加拦截
     */
    public boolean intercept(int type,List<String> targets, Date deadline,String remarks) {
        ToolError.isAndTrue(GMErrorCode.PARAM_ERR, "参数异常",CollUtil.isEmpty(targets));
        InterceptManager.addInterceptInfo(type, targets, deadline, remarks);
        return true;
    }

    /**
     * 移除拦截
     */
    public boolean removeIntercept(int...ids) {
        ToolError.isAndTrue(GMErrorCode.PARAM_ERR, "参数异常",ArrayUtil.isEmpty(ids));
        InterceptManager.removeInterceptInfo(ids);
        return true;
    }

    /**
     * 获取屏蔽信息，参数为类型数组
     */
    public List<String> getInterceptInfo() {
    	List<InterceptInfo> all = InterceptInfoCache.me().getCacheAll();
    	List<String> result = new ArrayList<>(all.size());
    	for (InterceptInfo interceptInfo : all) {
    		result.add(interceptInfo.toJson());
		}
        return result;
    }
}
